home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Communication / Weather / Source / MyMenuCell.m < prev    next >
Text File  |  1993-11-14  |  3KB  |  119 lines

  1. /*
  2.  * This menu cell is a cell in the weather menu browser.
  3.  * Knows how to transmit codes and fetch bits of text,
  4.  * which is somewhat special-cased for this service.
  5.  * M. J. Hawley
  6.  * mike@media-lab.mit.edu
  7.  * Copyright (c) November 1991, MIT Media Laboratory.
  8.  */
  9. #import "MyMenuCell.h"
  10. #import "Process.h"
  11. #import "Storm.h"
  12. #import "util.h"
  13. #import "state.h"
  14.  
  15. @implementation  MyMenuCell
  16.  
  17. void
  18. Say(char *fmt, ...) {
  19.     char s[1024];
  20.     va_list ap;
  21.     
  22.     va_start(ap, fmt);
  23.     vsprintf(s, fmt, ap);
  24.     setText(s);
  25.     va_end(ap);
  26. }
  27.  
  28. - click:sender {
  29.     if (*send == '!'){ // run a command
  30.         char t[1024], *p = send+1, *s;
  31.         *t = '\0'; sscanf(send+1,"%s",t);
  32.         if (*t && (s = path(t))){
  33.             p += strlen(t);
  34.             System("%s %s &",s,p);
  35.         } else
  36.             System("%s &",send+1);
  37.         setText("\nThat request is running quietly in the background.");
  38.         return self;
  39.     } else
  40.     if (*send == '|'){ // read from a pipe
  41.         char t[1024], *p = send+1, *s, ff[1024];
  42.         FILE *f;
  43.         *t = '\0'; sscanf(p,"%s",t);
  44.         if (*t && (s = path(t))){
  45.             p += strlen(t);
  46.             sprintf(ff,"%s %s",s,p);
  47.         } else
  48.             sprintf(ff,"%s",p);
  49.         if (f=popen(ff,"r")){
  50.             char buf[120000], *b = buf;
  51.             *b = '\0';
  52.             Say("\ntrying: %s...", ff);
  53.             while (fgets(b,sizeof b,f))
  54.                 b += strlen(b);
  55.             pclose(f);
  56.             setText(buf);
  57.         } else
  58.             setText("\nCouldn't fetch that data.");
  59.         return self;
  60.     } else
  61.     if (*send == '<'){ // open a file
  62.         char *p = send+1;
  63.         if (*p == '<'){ // ... via workspace
  64.             openFile(path(p+1));
  65.         } else
  66.             setFile(p); // ... locally
  67.         return self;
  68.     } else if (*send)
  69.         ensurelogin(), Put("%s",send);
  70.     if ([self isLeaf]) setFetchText(label);
  71.     if (strcmp("text",get)==0){
  72.         char buf[80000];
  73.         getReport(buf);
  74.         if (*buf) setText(buf);
  75.     }
  76.     return self;
  77. }
  78.  
  79. - click2:sender {
  80.     return self;
  81. }
  82.  
  83. - setStringValueNoCopy:(const char *)s {
  84.     label = getLabel((void *)s);
  85.     send = getSend((void *)s);
  86.     get = getGet((void *)s);
  87.     [super setStringValue:label];
  88.     [self setLeaf:state(get)?NO:YES];
  89.     //[self setAction:@selector(click:)];
  90.     [self setTarget:self];
  91.     return self;
  92. }
  93.  
  94. - setStringValue: (const char *)s {
  95.     return [self setStringValueNoCopy:s];
  96. }
  97.  
  98. - (char *)stringValue {
  99.     return label;
  100. }
  101.  
  102. - (char *)get {
  103.     return get;
  104. }
  105.  
  106. - send {
  107.     Put("%s",send);
  108.     return self;
  109. }
  110.  
  111. - mouseDown:(NXEvent *)e {
  112.     /* [super mouseDown:e]; */
  113.         if (e->data.mouse.click == 1){
  114.                 [self click:self];
  115.         }
  116.     return self;
  117. }
  118.  
  119. @end